package com.example.springbootdemo.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

// bean赋值、注入其他组件、@Autowired、生命周期注解注入、@Async。。。 都是通过 BeanPostProcessor 实现的
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    public MyBeanPostProcessor() {
        System.out.println("执行 MyBeanPostProcessor 构造函数");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor 初始化前的后处理:" + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor 初始化后的后处理:" + beanName);
        return bean;
    }
}
